package com.shizhanzhe.qdd.home.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.shizhanzhe.qdd.R;
import com.shizhanzhe.qdd.home.bean.StGrade;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author YJ
 * @date 2018/10/23
 */
public class ApprenticeExplainAdapter extends RecyclerView.Adapter<ApprenticeExplainAdapter.ViewHolder> {

    private Context mContext;
    private List<StGrade.DataBean> mData = new ArrayList<>();

    public ApprenticeExplainAdapter(Context context) {
        mContext = context;
    }

    public void updateData(int page, List<StGrade.DataBean> dataSet) {
        if (dataSet != null && !dataSet.isEmpty()) {
            if (page == 1) {
                mData = dataSet;
            } else {
                mData.addAll(dataSet);
            }
            notifyDataSetChanged();
        }
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_apprentice_explain, parent, false);
        return new ViewHolder(view);
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        StGrade.DataBean dataBean = mData.get(position);
        holder.level.setText(dataBean.getTdid()+"");
        holder.effectiveNum.setText(dataBean.getYnum()+" 人");
        holder.title.setText(dataBean.getName());
        holder.bonus.setText(dataBean.getMoney()+" 元");
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.level)
        TextView level;
        @BindView(R.id.effective_num)
        TextView effectiveNum;
        @BindView(R.id.title)
        TextView title;
        @BindView(R.id.bonus)
        TextView bonus;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
